#include"Queue.h"

void QueueInit(Queue* pq)
{
	assert(pq);
	pq->head = pq->tail = NULL;
}

void QueuePush(Queue* pq, StackType x)
{
	assert(pq);
	SQ* node = (SQ*)malloc(sizeof(SQ));
	if (node == NULL)
	{
		printf("malloc fail\n");
		exit(-1);
	}
	node->data = x;
	node->next = NULL;
	if (pq->tail == NULL)
	{
		pq->head = pq->tail = node;
	}
	else {
		pq->tail->next = node;
		pq->tail = node;
	}
}

void QueuePrint(Queue* pq)
{
	assert(pq);
	SQ* prev = pq->head;
	while (prev)
	{
		printf("%d ", prev->data);
		prev = prev->next;
	}
	printf("\n");
}

void QueuePop(Queue* pq)
{
	assert(pq);
	assert(pq->head);
	if (pq->head->next == NULL)
	{
		free(pq->head);
		pq->head = pq->tail = NULL;
	}
	else
	{
		SQ* next = pq->head->next;
		free(pq->head);
		pq->head = next;
	}
}